﻿// -----------------------------------------------------------------------
// <copyright file="OneImgOperation.cs" company="FCIS">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace LastVersionOfIpPackage.Operations
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text;

    /// <summary>
    /// the one image operation in ima ge algebra
    /// </summary>
    public class OneImgOperation
    {
        /// <summary>
        /// static object of this class to use this without create object
        /// </summary>
        private static OneImgOperation newNegativeOperation = new OneImgOperation();

        /// <summary>
        /// Gets or sets the new negative operation.
        /// </summary>
        /// <value>
        /// The new negative operation.
        /// </value>
        public static OneImgOperation NewNegativeOperation
        {
            get { return OneImgOperation.newNegativeOperation; }
            set { OneImgOperation.newNegativeOperation = value; }
        }

        /// <summary>
        /// Make the image negative.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// new image after negative
        /// </returns>
        public Bitmap MakeNegative(Bitmap image)
        {
            Color[,] bufferOfImage = BufferOfImage.Buffer.GetBuffer(image);
            Bitmap newImg = new Bitmap(bufferOfImage.GetLength(0), bufferOfImage.GetLength(1));
            try
            {
                for (int i = 0; i < bufferOfImage.GetLength(1); i++)
                {
                    for (int j = 0; j < bufferOfImage.GetLength(0); j++)
                    {
                        newImg.SetPixel(j, i, Color.FromArgb((int)255 - bufferOfImage[j, i].R, (int)255 - bufferOfImage[j, i].G, (int)255 - bufferOfImage[j, i].B));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                throw ex;
            }

            return newImg;
        }
    }
}
